. ./path.sh || exit 1;

stage=7
stop_stage=7

dir=/home/work_nfs6/xlgeng/new_workspace/wenet_gxl_en_cn/streaming_fbank_exp/small_2

if [ ${stage} -le 6 ] && [ ${stop_stage} -ge 6 ]; then
  echo '开始导出模型'
  # Export the best model you want
  python wenet/bin/export_jit.py \
    --config $dir/train.yaml \
    --checkpoint $dir/epoch_9.pt \
    --output_file $dir/final_9.zip \
    --output_quant_file $dir/final_quant.zip
fi

if [ ${stage} -le 7 ] && [ ${stop_stage} -ge 7 ]; then
  echo "开始推理"
  export GLOG_logtostderr=1
  export GLOG_v=2
  wav_path=/home/work_nfs7/xlgeng/new_workspace/wenet_gxl_en_cn/examples/aishell/en_cn/data_list/tiny_asru_test.scp
  /home/work_nfs7/xlgeng/workspace/wenet-sanm/runtime/libtorch/build/bin/decoder_main \
      --chunk_size 16 \
      --wav_scp $wav_path \
      --model_path $dir/final_9.zip \
      --unit_path data_list/units_en_cn.txt \
      --result  $dir/jit_out_text
fi

if [ ${stage} -le 8 ] && [ ${stop_stage} -ge 8 ]; then
  echo "开始网络服务器"
  export GLOG_logtostderr=1
  export GLOG_v=2
  wav_path=/home/work_nfs7/xlgeng/workspace/wenet-sanm/examples/aishell/en_cn/data/asru_test.scp
  /home/work_nfs7/xlgeng/workspace/wenet-sanm/runtime/libtorch/build/bin/websocket_server_main \
      --port 10086 \
      --chunk_size 16 \
      --model_path $dir/final_9.zip \
      --unit_path data_list/units_en_cn.txt 2>&1 | tee server.log
fi


if [ ${stage} -le 9 ] && [ ${stop_stage} -ge 9 ]; then
  echo "开始网络客户端"
  export GLOG_logtostderr=1
  export GLOG_v=2
  wav_path="/home/work_nfs6/disk2/ASR_data/wav/ASRU700/T0055G0464S0097.wav"
  /home/work_nfs7/xlgeng/workspace/wenet-sanm/runtime/libtorch/build/bin/websocket_client_main \
    --hostname 127.0.0.1 --port 10086 \
    --wav_path $wav_path 2>&1 | tee client.log
fi